package zy.test.serviceuse;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.util.Log;

public class BindService extends Service {

	private final IBinder myBinder=new MyBinder();
	
	
	@Override
	public IBinder onBind(Intent intent) {
		System.out.println("bind-service bind");
		new TestThread().start();
		return myBinder;
	}
	
	public class MyBinder extends Binder
	{
		public BindService getService()
		{
			return BindService.this;
		}
	}
	
	@Override
	public void onCreate() {
		super.onCreate();
		System.out.println("bind-service create");
	}
	
	@Override
	public boolean onUnbind(Intent intent) {
		System.out.println("bind-service unbind");
		//testThreadEnd=true;
		return super.onUnbind(intent);
	}
	
	@Override
	public void onDestroy() {
		super.onDestroy();
		System.out.println("bind-service destroy");
	}
	
	private long testCount=1;
	boolean testThreadEnd=false;
	class TestThread extends Thread
	{
		@Override
		public void run() {
			super.run();
			while(!testThreadEnd)
			{
				if(testCount%430000==0)
				Log.w("cou", testCount+"");
				testCount++;
				if(testCount>5430000)
					stopSelf();
			}
		}
	}
	
	public long getCount()
	{
		return testCount;
	}
	
	

}
